<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">

				<el-col :lg="24" v-if="form.collect_status==1">
					<el-form-item label="企业名称"   prop="name">
						<el-input v-model="form.name" placeholder="企业名称" clearable maxlength="100" :disabled="true"></el-input>
						<el-tag   type="warning" effect="dark" size="medium " v-if="form.collect_status==1">目标客户</el-tag>
					</el-form-item>
				</el-col>
				<el-col :lg="24" v-else>
					<el-form-item label="企业名称"   prop="name">
						<el-input v-model="form.name" placeholder="企业名称" clearable maxlength="100" :disabled="true"></el-input>
					</el-form-item>
				</el-col>
			 </el-row>
			 <el-row :gutter="24">
				<el-col :lg="24">
					<el-form-item label="备注" >
						<sc-editor v-model="form.remark" placeholder="请输入" :templates="templates" :height="300" clearable  style="width: 100%;"></sc-editor>
					</el-form-item>
				</el-col>
			</el-row>


			<!-- <el-form-item label="相关附件" prop="attachId">
				<sc-upload-file :apiObj="apiObj"  v-model="fileList" :data="{module:'supervision'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item> -->
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import {defineAsyncComponent} from "vue";
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
	emits: ['success', 'closed'],
	components: {
		scEditor
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg:false,
			mode: "add",
			templates: [],
			fileList:[],
			userList:[],
			title:"",
			apiObj:this.$API.file.attach.uploadFile,
			titleMap: {
				add: '目标客户',
				edit: '目标客户',
			},
			form: {
				tid:'2',
				collect_status:'0',
				id:'',
				ep_id:'',
				remark: '',
				attachId:'',
			},
			rowData:{},
			rules: {
				title: [
					{required: true, message: '任务标题不能为空', trigger: 'blur'}
				],
				holder: [
					{required: true, message: '主办人不能为空', trigger: 'blur'}
				],
				operatorArr: [
					{required: true, message: '经办人不能为空', trigger: 'blur'}
				],
				beginTime: [
					{required: true, message: '开始时间不能为空', trigger: 'blur'}
				],
				endTime: [
					{required: true, message: '结束时间不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		publishDateAfter(time){
			return time.getTime()<(Date.now()-24*60*60*1000)
		},
		async getCollectUserForSelect(){
			let res = await this.$API.supervision.supervisionConfig.getSupervisionHandedUserForSelect.get({ep_id:this.form.ep_id});
			if (res.code == 200) {
				this.userList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit() {
			this.form.collect_status="1";
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					if(this.form.operatorArr!=null)
					{
						this.form.operator = this.form.operatorArr.join(",");
					}
					let data = {list:JSON.stringify([this.rowData]),remark:this.form.remark}
					// var res = await this.$API.enterprise.company.setTargetEpData.post(this.form);
					var res = await this.$API.enterprise.adaptationAnalysis.saveCollectCompanyTarget.post(data);

					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})



		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
		setData(data) {
			this.form.name = data.name
			this.form.id = data.id
			this.form.ep_id = data.ep_id
			this.form.remark = data.remark
			this.form.collect_status= data.collect_status
			this.rowData = data;
		},
	}
}
</script>

<style>
.customWidth {
	width: 40%;
}
</style>
